﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;

namespace KELT.Controls.Timeline.TimelineGroup
{
    public class ObjectItem : TreeViewItem
    {
        static ObjectItem()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(ObjectItem), new FrameworkPropertyMetadata(typeof(ObjectItem)));
        }

        public ObjectItem()
        {
        }
        
        protected override DependencyObject GetContainerForItemOverride()
        {
            return new ObjectItem();
        }

        protected override bool IsItemItsOwnContainerOverride(object item)
        {
            return item is ObjectItem;
        }
        
        public event PropertyChangedEventHandler PropertyChanged;

        public int Level
        {
            get
            {
                if (_level == -1)
                {
                    ObjectItem parent = ItemsControl.ItemsControlFromItemContainer(this) as ObjectItem;
                    _level = (parent != null) ? parent.Level + 1 : 0;
                }

                return _level;
            }
        }

        private int _level = -1;


        private string _groupId;

        public string GroupId
        {
            set
            {
                _groupId = value;

                OnPropertyChanged("GroupId");
            }

            get
            {
                return _groupId;
            }
        }

        private string _groupName;

        public string GroupName
        {
            set
            {
                _groupName = value;
                OnPropertyChanged("GroupName");
            }

            get
            {
                return _groupName;
            }
        }

        protected void OnPropertyChanged(string name)
        {
            PropertyChangedEventHandler handler = PropertyChanged;

            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(name));
            }
        }
    }
}
